using System.Collections.Generic;
using System.Text;
using System;

namespace NExt.UI.Base.Right
{
    public class CompositeRightSetter : RightSetterScript
    {
        private readonly IList<IRightSetterScript> rightSetterScriptList;
        private const string FUNCTION_NAME = "CompositeRightSetter";
        private const string PARAMETER_TEXT_FORMAT = "{{rightSetterList :  [{0}]}}";

        private CompositeRightSetter(IList<IRightSetterScript> rightSetterScriptList, params string[] parameterNames)
            : base(FUNCTION_NAME, parameterNames)
        {
            this.rightSetterScriptList = rightSetterScriptList;
        }

        public static RightSetterScript Create(IEnumerable<IRightSetterScript> rightSetterScripts)
        {
            List<IRightSetterScript> rightSetterScriptList = new List<IRightSetterScript>(rightSetterScripts);
            string[] rightSetters = new string[rightSetterScriptList.Count];
            for (int i = 0; i < rightSetters.Length; i++)
            {
                rightSetters[i] = rightSetterScriptList[i].text;
            }
            string parameter = string.Join(",", rightSetters);
            parameter = string.Format(PARAMETER_TEXT_FORMAT, parameter);
            CompositeRightSetter compositeRightSetter = new CompositeRightSetter(rightSetterScriptList, parameter);

            return compositeRightSetter;
        }

        public static RightSetterScript Create(params IRightSetterScript[] rightSetterScripts)
        {
            return Create((IEnumerable<IRightSetterScript>)rightSetterScripts);
        }

        public IList<IRightSetterScript> RightSetterScriptList
        {
            get { return rightSetterScriptList; }
        }
    }
}